@extends('admin.home.main')

@section('body')
<section id="main-content">
	  <section class="wrapper">
		<h3>测试项目编辑</h3>
		<!-- BASIC FORM ELELEMNTS -->
		<div class="row mt">
		  <div class="col-lg-12">
			<div class="form-panel">
			  <form class="form-horizontal style-form" action="/admin/coursetype/insert" method="post">
			  	<input type="hidden" id="_token" name="_token" value="{{csrf_token()}}">
			  	<input type="hidden" name="id" id="id" value="{{$info->id}}">
			  	<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">选择标签</label>
				  <div class="col-sm-10">
					  @foreach($taglist as $tm=>$ts)
						  @if(in_array($ts->id,$info->tag_id))
							  <input type="checkbox" class="tag_list" value="{{$ts->id}}"
									 checked="checked">{{$ts->tag_name}}
						  @else
							  <input type="checkbox" class="tag_list" value="{{$ts->id}}">{{$ts->tag_name}}
						  @endif
					  @endforeach
				  </div>
				</div>

				<div class="form-group">
				  	<label class="col-sm-2 col-sm-2 control-label">是否多选</label>
				  	<div class="col-sm-10">
						<input type="radio" name="is_muti" class="ismuti" value="1" @if($info->multi == 1) checked="checked" @endif>多选
						<input type="radio" name="is_muti" class="ismuti" value="0" @if($info->multi == 0) checked="checked" @endif)>单选
				  	</div>
				</div>

				<div class="form-group">
				  <label class="col-sm-2 col-sm-2 control-label">题库项目名称</label>
				  <div class="col-sm-10">
					<input type="text" style="width:400px;" class="form-control" id="name" name="name" placeholder="请输入题库项目名称" size="50" value="{{$info->question}}">
				  </div>
				</div>

				
				<button type="button" id="save" class="btn btn-success">提交</button>
				<button type="reset" class="btn btn-primary">重置</button>
			  </form>
			</div>
		  </div>
		  <!-- col-lg-12-->
		</div>

		
	  </section>
	  <!-- /wrapper -->
	</section>
<script type="text/javascript">
	$('#save').click(function(){
		var _id = $('#id').val(),
			_tag_id = [],
			_token = $('#_token').val(),
			_ismuti = '',
			_itemname = $('#name').val();

		$('.tag_list').each(function(){
			if($(this).is(':checked')){
				_tag_id.push($(this).val());
			}
		})

		_tag_id = _tag_id.join(',');
		$('.ismuti').each(function(){
			if($(this).is(':checked')){
				_ismuti = $(this).val();
			}
		})

		if(!_itemname){
			alert('请输入栏目名称');
			return false;
		} 

		$.ajax({
			url:'/admin/item_bank/save',
			type:'post',
			data:{'id':_id,'tag_id':_tag_id,'ismuti':_ismuti,'_token':_token,'question':_itemname},
			dataType:'json',
			success:function(msg){
				if(msg.code == 200){
					alert('编辑成功');
					location.href="/admin/item_bank/list";
				}else{
					alert('编辑失败');
					location.reload();
				}
			}
		})
	})
</script>
@endsection